Completed
Push — master ( 1b4532...54964d )
by Andres
01:14
created

angular.controller(ꞌmain-loopꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 0
1
'use strict';
2
3
angular
4
  .module('game')
5
  .controller('main-loop', ['$scope',
6
    '$interval',
7
    '$timeout',
8
    'savegame',
9
    'achievement',
10
    'util',
11
    'format',
12
    'reaction',
13
    'data',
14
    'visibility',
15
    'state',
16
    function($scope, $interval, $timeout, savegame, achievement, util, format, reaction, data, visibility, state) {
17
      $scope.data = data;
18
      $scope.achievement = achievement;
19
      $scope.util = util;
20
      $scope.format = format;
21
      $scope.reaction = reaction;
22
      $scope.visibility = visibility;
23
      $scope.state = state;
24
25
      let self = this;
26
      let playerCopy = null;
27
28
      self.update = function() {
29
        // do the update in a copy
30
        playerCopy = angular.copy(state.player);
31
        achievement.checkAchievements(playerCopy);
32
33
        state.update(playerCopy);
34
35
        // and update all at once
36
        state.player = playerCopy;
37
38
        $timeout(self.update, 1);
39
      };
40
41
      function save() {
42
        localStorage.setItem('playerStoredITE', JSON.stringify(state.player));
43
      }
44
45
      self.startup = function() {
46
        savegame.load();
47
        state.loading = false;
48
        $timeout(self.update, 1000);
49
        $interval(save, 10000);
50
      };
51
52
      $timeout(self.startup);
53
    }
54
  ]);
55